package com.duang.framework.render;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.duang.framework.core.Constants;


/**
 * TextRender.
 */
public class TextRender extends AbstractContentViewRender {

	private static final String DEFAULT_CONTENT_TYPE = "text/plain; charset="
			+ Constants.DEFAULT_ENCODING;

	@Override
	public void render(String content, HttpServletRequest req,
			HttpServletResponse resp) throws RenderException {
		PrintWriter writer = null;
		try {
			resp.setHeader("Pragma", "no-cache"); // HTTP/1.0 caches might not
													// implement Cache-Control
													// and might only implement
													// Pragma: no-cache
			resp.setHeader("Cache-Control", "no-cache");
			resp.setDateHeader("Expires", 0);
			resp.setContentType(DEFAULT_CONTENT_TYPE);
			writer = resp.getWriter();
			writer.write(content);
			writer.flush();
		} catch (IOException e) {
			throw new RenderException(e);
		} finally {
			if (writer != null)
				writer.close();
		}
	}
}
